﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom.Compiler;
using System.Web;

namespace Medianamik.Core.CodeGeneration
{
    public  class CodeGenerationResult
    {

        private CompilerResults _compilerResults;

        public TimeSpan Duration { get; private set;}

        public string FinalCode { get; private set; }

        public bool HasErrors 
        { 
            get 
            { 
                return _compilerResults == null ? false : _compilerResults.Errors.Count > 0; 
            } 
        }

        public IEnumerable<string> CompilerOutput
        {
            get
            {
                if (_compilerResults != null)
                {
                    foreach (string s in _compilerResults.Output)
                    {
                        yield return s;
                    }
                }
            }
        }
        public IEnumerable<CompilerError> Errors
        {
            get
            {
                if (_compilerResults != null)
                {
                    foreach (CompilerError error in _compilerResults.Errors)
                    {
                        yield return error;
                    }
                }
            }
        }

        internal CodeGenerationResult(string pFinalCode, CompilerResults pCodeDomCompilerResults, TimeSpan pDuration )
        {
            _compilerResults = pCodeDomCompilerResults;
            FinalCode = pFinalCode;
            Duration = pDuration;
        }




        
            
    }
}
